/***************** Modification History ***********************************
   @doc
   @module fct.c - Function Control Table functions |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/CONTROL/fct.c $ 
---------------------------------------------------------------------------

   Copyright (C) 1996 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#define FCT_C
#include <varrec.h>

#include <project.h>
#ifdef DEBUG_FCT
#define DEBUG_95
#endif

#include <define.h>
#include <transact.h>
#include <file.h>
#include <confio.h>
#include <fct.h>


/* #ifdef CONTROLS */

const char* szGlobalFCTFileName = "fct.dat";
extern unsigned char* gpsrFunctionRecord;


/********************************************************************************************* 
* @func int | inProcessFCT | 
*       Scans the FlexiRecord setting the attributes to indicate which
*       Functions are enabled/disabled.
*
* @parm NONE | 
*
* @rdesc Return values.
* @flag int    |  VS_SUCCESS    |
* @flag int    |  VS_ERR        |
* @end
**********************************************************************************************/

int inProcessFCT(TRANSACTION_OBJECT* pobTran) {
    long lnFileSize;
    int inNumRecords,
    inRecNo,
    inFieldNo;
    unsigned char   ucAttributes;
    FCT_REC srFCTRec;

    lnFileSize = lnGetFileSize(szGlobalFCTFileName);
    inNumRecords = ((int) ((lnFileSize - GEN_VER_SIZE) / (long) SIZE_FCT_REC));

    for (inRecNo = 0; inRecNo < inNumRecords; inRecNo++) {
        /* If the FCT has been altered it must be processed here*/
        if (inLoadConfRec(szGlobalFCTFileName, SIZE_FCT_REC, inRecNo, (char *) &srFCTRec) != VS_SUCCESS)
            return(VS_ERROR);

        if (srFCTRec.shDisabled)
            ucAttributes = VAR_ATT_READ_ONLY;
        else
            ucAttributes = VAR_ATT_READ_WRITE;
        inFieldNo = 0;

        while (srFCTRec.inFunctionId[inFieldNo] && inFieldNo < MAX_FUNCTIONS) {
            shVarUpdateFieldAtt(gpsrFunctionRecord, srFCTRec.inFunctionId[inFieldNo], ucAttributes);
            inFieldNo++;
        }
    }
    return(VS_SUCCESS);
}

/*#endifCONTROLS*/
#undef FCT_C
